import { http } from './http'
import { PageQueryParams, PageResponse } from '@/config/page'

export interface LinkDocQueryParams extends PageQueryParams {
  docParentId?: number;

  accessCode?: string;

  docType?: string;
}

/**
 * 获取链接
 * @param id
 * @returns
 */
export function getDocLink (id: number, accessCode?: string) {
  return http().get<any>(`/api/document/ignores/doc-shares/${id}`, { params: { accessCode } })
}

/**
 * 校验提取码是否正确。
 * @param id
 * @param accessCode
 * @returns
 */
export function checkAccessCode (id: number, accessCode: string) {
  return http().get<any>(`/api/document/ignores/doc-shares/${id}/check`, { params: { accessCode } })
}

/**
 * 获取外链文件列表。
 */
export function queryDocsByLink (id: number, params: LinkDocQueryParams): Promise<PageResponse<any>> {
  return http().get<PageResponse<any>>(`/api/document/ignores/doc-shares/${id}/docs`, { params })
}

/**
 * 获取外链文档。
 */
export function getDocByLink (id: number, docId: number) {
  return http().get<PageResponse<any>>(`/api/document/ignores/doc-shares/${id}/docs/${docId}`)
}

/**
 * 下载文档。
 */
export function downloadDoc (id: number, docId: string, accessCode?: string) {
  return http().get<any>(`/api/document/ignores/doc-shares/${id}/download/${docId}`, { params: { accessCode } })
}

/**
 * 打包下载文档。
 * @param params
 */
export function downloadDocWithPackage (id: number, ids: number[], accessCode?: string): Promise<string> {
  return http().post<any>(`/api/document/ignores/doc-shares/${id}/package/download`, { ids }, { params: { accessCode }, responseType: 'blob', timeout: 0 })
}

/**
 * 下载文档。
 */
export function previewDoc (id: number, docId: string, accessCode?: string) {
  return http().get<any>(`/api/document/ignores/doc-shares/${id}/preview/${docId}`, { params: { accessCode } })
}
